MYLIB=libclean-utils.a
PROGS=code-cleaner parsingUtilTest ${MYLIB}
CC=gcc
CFLAGS=-Wall -pedantic -g -std=c99 -D_GNU_SOURCE
LINKLIBRARY=-static -L. -lclean-utils
VERSION=

all: ${PROGS}

logger.o: logger.c logger.h
	${CC} ${CFLAGS} logger.c -c -o logger.o

fileLockHelper.o: fileLockHelper.c fileLockHelper.h
	${CC} ${CFLAGS} fileLockHelper.c -c -o fileLockHelper.o

parsingUtils.o: parsingUtils.c parsingUtils.h logger.o fileLockHelper.o
ifeq ($(VERSION),SNAIL)
	${CC} ${CFLAGS} -DSNAIL_VERSION parsingUtils.c -c -o parsingUtils.o
else
	${CC} ${CFLAGS} parsingUtils.c -c -o parsingUtils.o
endif

#create a static library that can be used by the main program and the unit test program 
${MYLIB}: logger.o parsingUtils.o fileLockHelper.o
	ar rcs libclean-utils.a logger.o parsingUtils.o fileLockHelper.o
#	rm *.o
	
code-cleaner: code-cleaner.c ${MYLIB}
	${CC} ${CFLAGS} code-cleaner.c -o code-cleaner ${LINKLIBRARY}

parsingUtilTest: parsingUtilTest.c ${MYLIB} 
	${CC} ${CFLAGS} parsingUtilTest.c  -o parsingUtilTest ${LINKLIBRARY}
	
#this target will compile and run the unit tests
test: parsingUtilTest
	@echo 'Executing the parsingUtilTest!'
	./parsingUtilTest
	
.PHONY: clean test

clean:
	rm -f ${PROGS} *.log *.o *.a ./testFile/*.clean *~ .swp
